#include "RtpPacket1.h"
#include "Packet.h"
#include "MyAssert.h"

RTPPacket1::RTPPacket1( UInt16 size )
{
	Assert( size > RTP_HEAD_LEN );
	buffer = new UInt8[ size ];
	bufferSize = size;

	payload = buffer + RTP_HEAD_LEN;
	payloadSize = bufferSize - RTP_HEAD_LEN;
	SetVersion( RTP_VERSION_CONST);
	SetPayLoadType( RTP_PAYLOADTYPE_CONST);
	SetSSRC( RTP_SSRC_CONST);
}

RTPPacket1::~RTPPacket1(void)
{
	if( buffer != NULL ) {
		delete[] buffer;
	}

}



Int32 RTPPacket1::SetPayLoad(const UInt8 * pData,UInt32 size ) {
	Assert ( size == payloadSize );
	memcpy( payload ,pData, size );
	return 0;
}


UInt8	RTPPacket1::GetVersion() {
	return buffer[RTP_VERSION_OFFSET];
}

Int32		RTPPacket1::SetVersion(UInt8 version) {
	buffer[RTP_VERSION_OFFSET] = version ;
	return 0;
}

UInt8  RTPPacket1::GetPayLoadType() {
	return	buffer[RTP_PAYLOADTYPE_OFFSET];
}


Int32  RTPPacket1::SetPayLoadType(UInt8 payLoadType ) {
	buffer[RTP_PAYLOADTYPE_OFFSET ] =  payLoadType  ;
	return 0;
}

UInt16 RTPPacket1::GetSeqNum () {
	return ntohs( *(UInt16*)(buffer+RTP_SEQ_NUM_OFFSET )  );
}

Int32		RTPPacket1::SetSeqNum(UInt16 seqNum) {
	*(UInt16*)(buffer+RTP_SEQ_NUM_OFFSET) = htons(seqNum);
	return 0;
}

UInt32  RTPPacket1::GetTimeStamp( ) {
	return  ntohl( *( UInt32* )( buffer+RTP_TIME_STAMP_OFFSET ) );
}

Int32 RTPPacket1::SetTimeStamp( UInt32 timeStamp ) {
	*(UInt32*)(buffer+RTP_TIME_STAMP_OFFSET) = htonl(timeStamp);
	return 0;
}


UInt32  RTPPacket1::GetSSRC()  {
	return  ntohl( *( UInt32* )( buffer+RTP_SSRC_OFFSET ) );
}

Int32 RTPPacket1::SetSSRC( UInt32 ssrc ) {
	*(UInt32*)(buffer+RTP_SSRC_OFFSET) = htonl(ssrc);
	return 0;
}

Bool RTPPacket1::SetFirstFlag(void)
{
	payload[0]|=0x80;
	return TRUE;
}
#ifdef  DEBUG

//extern Int32 printf(LPCTSTR pszFormat, ...);


Int32 RTPPacket1::Test() {				// for Debug
	RTPPacket1 packet( 50 );
	packet.SetVersion( 20 );
	packet.SetPayLoadType( 96);
	packet.SetTimeStamp( TIMESCALE );
	UInt8 pay[50-12];
	packet.SetPayLoad(pay, 50-12);
	packet.PacketOut();
	return 0;
}

Int32 RTPPacket1::PacketOut() {

	return 0;
}



# endif 







